CFLAGS=-I./sources
LIBS=-L/usr/X11R6/lib -L./lib -lGL -lGLU -lglut -lSDL -lSDLmain
CC=g++
MAKEF=true
  
install: checkRequestForInstall
	cp -fip lib/* /usr/lib

checkRequestForInstall:
	if [ ! -f "lib/libalgebric.so.1.0.1" ]; then printf "-lib/libalgebric.so.1.0.1- not exists, please compile the sources!" ; fi
	if [ ! -f "lib/libfuengine.so.1.0.1" ]; then printf "-lib/libfuengine.so.1.0.1- not exists, please compile the sources!" ; fi

all: libalgebric libfuengine

libfuengine : lib/libfuengine.so.1.0.1
libalgebric : lib/libalgebric.so.1.0.1

lib/libfuengine.so.1.0.1: checkRequest bins/GLBitmap.o bins/Q3OObjectData.o bins/ISceneManagement.o bins/CollisionManager.o bins/IMovingSphere.o
	$(CC) -shared $(CFLAGS)  $(LIBS) -lalgebric -Wl,-soname,libfuengine.so.1 -o libfuengine.so.1.0.1 -lc  bins/*.o  	
	ln -s libfuengine.so.1.0.1 libfuengine.so.1
	ln -s libfuengine.so.1.0.1 libfuengine.so
	mv libfuengine* lib	

lib/libalgebric.so.1.0.1: checkRequestAlgebric bins/math/GeoMath.o bins/math/Analysis.o bins/math/Vector2.o bins/math/Vector3.o bins/math/Matrix2.o bins/math/Matrix3.o
	$(CC) -shared -Wl,-soname,libalgebric.so.1 -o libalgebric.so.1.0.1 -lc bins/math/*.o 	
	ln -s libalgebric.so.1.0.1 libalgebric.so.1
	ln -s libalgebric.so.1.0.1 libalgebric.so
	mv libalgebric* lib

checkRequestAlgebric:
	if [ ! -d "bins" ]; then mkdir "bins" ; fi
	if [ ! -d "bins/math" ]; then mkdir "bins/math" ; fi

clean:
	rm -f bins/*.o
	rm -f bins/math/*.o
	rm -f lib/libalgebric*
	rm -f lib/libfuengine*

checkRequest:
	if [ ! -d "bins" ]; then mkdir "bins" ; fi

# SCENE CLASSES
# _____________________________________________________________________________________________

bins/ISceneManagement.o: bins/ImmutableObject.o bins/SceneRenderer.o sources/ISceneManagement.h sources/ISceneManagement.cpp
	$(CC) -fPIC -c sources/ISceneManagement.cpp $(CFLAGS)
	mv ISceneManagement.o bins/ISceneManagement.o

bins/SceneRenderer.o: bins/IInputHandler.o bins/Camera.o sources/SceneRenderer.h sources/SceneRenderer.cpp
	$(CC) -fPIC -c sources/SceneRenderer.cpp $(CFLAGS)
	mv SceneRenderer.o bins/SceneRenderer.o


# 3D OBJECT CLASSES
# _____________________________________________________________________________________________


bins/ImmutableObject.o:	bins/ListIDContainer.o bins/SceneObject.o sources/ImmutableObject.h sources/ImmutableObject.cpp
	$(CC) -fPIC -c sources/ImmutableObject.cpp $(CFLAGS)
	mv ImmutableObject.o bins/ImmutableObject.o

bins/ListIDContainer.o:	sources/ListIDContainer.h sources/ListIDContainer.cpp
	$(CC) -fPIC -c sources/ListIDContainer.cpp $(CFLAGS)
	mv ListIDContainer.o bins/ListIDContainer.o

bins/SceneObject.o:	bins/SceneNode.o bins/CollisionHul.o  bins/RawObjectData.o sources/SceneObject.h sources/SceneObject.cpp
	$(CC) -fPIC -c sources/SceneObject.cpp $(CFLAGS)
	mv SceneObject.o bins/SceneObject.o



# INPUT CLASSES
# _____________________________________________________________________________________________
bins/IInputHandler.o: sources/IInputHandler.h sources/IInputHandler.cpp
	$(CC) -fPIC -c sources/IInputHandler.cpp $(CFLAGS)
	mv IInputHandler.o bins/IInputHandler.o


# VIEW CLASSES
# _____________________________________________________________________________________________

bins/Camera.o: sources/Camera.h sources/Camera.cpp
	$(CC) -fPIC -c sources/Camera.cpp $(CFLAGS)
	mv Camera.o bins/Camera.o

# 3D OBJECT FORMAT CLASSES
# _____________________________________________________________________________________________


bins/Q3OObjectData.o:	bins/RawObjectData.o sources/Q3O_Types.h sources/Q3OObjectData.h sources/Q3OObjectData.cpp 
	$(CC) -fPIC -c sources/Q3OObjectData.cpp $(CFLAGS)
	mv Q3OObjectData.o bins/Q3OObjectData.o

bins/RawObjectData.o:bins/Color.o bins/GLTexture.o sources/RawObjectData.h sources/RawObjectData.cpp
	$(CC) -fPIC -c sources/RawObjectData.cpp $(CFLAGS)
	mv RawObjectData.o bins/RawObjectData.o


# BASE ENGINE CLASSES
# _____________________________________________________________________________________________


bins/SceneNode.o:	bins/BaseRenderObject.o sources/SceneNode.h sources/SceneNode.cpp 
	$(CC) -fPIC -c sources/SceneNode.cpp $(CFLAGS)
	mv SceneNode.o bins/SceneNode.o

bins/BaseRenderObject.o:	sources/BaseRenderObject.h sources/BaseRenderObject.cpp
	$(CC) -fPIC -c sources/BaseRenderObject.cpp $(CFLAGS)
	mv BaseRenderObject.o bins/BaseRenderObject.o



# PIC CLASSES
# _____________________________________________________________________________________________
bins/GLBitmap.o: sources/GLBitmap.h sources/GLBitmap.cpp
	$(CC) -fPIC -c sources/GLBitmap.cpp $(CFLAGS)
	mv GLBitmap.o bins/GLBitmap.o

bins/GLTexture.o: sources/GLTexture.h sources/GLTexture.cpp
	$(CC) -fPIC -c sources/GLTexture.cpp $(CFLAGS)
	mv GLTexture.o bins/GLTexture.o

bins/Color.o:	sources/Color.h sources/Color.cpp
	$(CC) -fPIC -c sources/Color.cpp $(CFLAGS)
	mv Color.o bins/Color.o


# COLLISION CLASSES
# _____________________________________________________________________________________________
bins/IMovingSphere.o: bins/CollisionManager.o sources/IMovingSphere.h sources/IMovingSphere.cpp
	$(CC) -fPIC -c sources/IMovingSphere.cpp $(CFLAGS)
	mv IMovingSphere.o bins/IMovingSphere.o

bins/CollisionManager.o: bins/CollisionHul.o sources/CollisionManager.h sources/CollisionManager.cpp
	$(CC) -fPIC -c sources/CollisionManager.cpp $(CFLAGS)
	mv CollisionManager.o bins/CollisionManager.o

bins/CollisionHul.o:   sources/CollisionHul.h sources/CollisionHul.cpp
	$(CC) -fPIC -c sources/CollisionHul.cpp $(CFLAGS)
	mv CollisionHul.o bins/CollisionHul.o

# MATH AND GEO CLASSES
# _____________________________________________________________________________________________

bins/math/GeoMath.o: sources/math/GeoMath.h sources/math/GeoMath.cpp
	$(CC) -fPIC -O -c sources/math/GeoMath.cpp $(CFLAGS)
	mv GeoMath.o bins/math/GeoMath.o

bins/math/Analysis.o: sources/math/Analysis.h sources/math/Analysis.cpp
	$(CC) -fPIC -O -c sources/math/Analysis.cpp $(CFLAGS)
	mv Analysis.o bins/math/Analysis.o

bins/math/Matrix3.o: bins/math/GeoMath.o sources/math/Matrix3.h sources/math/Matrix3.cpp
	$(CC) -fPIC -O -c sources/math/Matrix3.cpp $(CFLAGS)
	mv Matrix3.o bins/math/Matrix3.o

bins/math/Vector3.o: bins/math/GeoMath.o sources/math/Vector3.h sources/math/Vector3.cpp
	$(CC) -fPIC -O -c sources/math/Vector3.cpp $(CFLAGS)
	mv Vector3.o bins/math/Vector3.o

bins/math/Matrix2.o: sources/math/Matrix2.h sources/math/Matrix2.cpp
	$(CC) -fPIC -O -c sources/math/Matrix2.cpp $(CFLAGS)
	mv Matrix2.o bins/math/Matrix2.o

bins/math/Vector2.o: sources/math/Vector2.h sources/math/Vector2.cpp
	$(CC) -fPIC -O -c sources/math/Vector2.cpp $(CFLAGS)
	mv Vector2.o bins/math/Vector2.o

